package org.jeecg.modules.rooms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.rooms.entity.CesHouseLongRentScheme;
import org.jeecg.modules.rooms.mapper.CesHouseLongRentSchemeMapper;
import org.jeecg.modules.rooms.service.ICesHouseLongRentChargeService;
import org.jeecg.modules.rooms.service.ICesHouseLongRentSchemeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CesHouseLongRentSchemeServiceImpl extends ServiceImpl<CesHouseLongRentSchemeMapper, CesHouseLongRentScheme> implements ICesHouseLongRentSchemeService {

    @Resource
    private ICesHouseLongRentChargeService houseLongRentChargeService;

    @Override
    public void addLivingScheme(CesHouseLongRentScheme scheme,String livingOrderId) {
        if (scheme == null || StrUtil.isEmpty(scheme.getId())) {
            throw new JeecgBootException("请选择长租房方案");
        }
        scheme.getHouseLongRentChargeList().forEach(e -> {
            e.setId(null);
            e.setSchemeId(scheme.getId());
            e.setLivingOrderId(livingOrderId);
        });
        houseLongRentChargeService.saveBatch(scheme.getHouseLongRentChargeList());
    }
}
